 begintownscript;
variables;
short choice,i,j,level;

body;
beginstate init_state;
i = 0;
while(char_ok(i) == 0){
	i = i + 1;
}
if(get_flag(9,0) > 0){
	message_dialog("I was already late-- it was a rush delivery and I was supposed to have delivered the package that very night. Still I rushed on, hoping to at least recover the package and deliver it rather than show up empty-handed.","The journey to the cart site took frustratingly longer than I anticipated. I was on foot this time, and was still feeling the effects of the fear dust.");
	message_dialog("The sun had just risen above the tops of the trees ahead when I finally saw the tipped over cart lying in the road. I rushed forward, holding my breath waiting to see if the package was still beneath the seat.","I was in a world of trouble if it wasn't-- I was in a world of trouble already.");
	set_terrain(7,13,0);
	set_terrain(8,13,0);
	erase_char(6);
	set_ticks_forward(0 - get_current_tick());
	force_instant_terrain_redraw();
	end();
}
set_terrain(22,14,0);
set_terrain(23,14,0);
set_terrain(22,15,0);
set_terrain(24,15,0);
set_terrain(22,17,0);
set_terrain(21,11,0);
set_terrain(23,15,0);
set_char_dialogue_pic(7,300,0);
set_name(7,"Highwayman");

relocate_character(i,7,13);
force_view_center(7,13);
set_character_facing(i,2);
set_character_pose(i,8);
force_instant_terrain_redraw();

j = 0;
while(j <= 22){
	set_char_trait(i,j,0);
	j = j + 1;
}
set_char_trait(i,6,1);

level = get_level(i);
set_level(i,15);
while(level > 1){
	change_char_xp(i,-25 * 100);
	level = level - 1;
}
level = 15;
while(level > 1){
	change_char_xp(i,500);
	change_char_xp(i,500);
	change_char_xp(i,200);
	level = level - 1;
}
j = 0;
while(j <= 19){
	if(get_spell_level(i,0,j) > 0)
		change_spell_level(i,0,j,-1* get_spell_level(i,0,j));
	if(get_spell_level(i,1,j) > 0)
		change_spell_level(i,1,j,-1 * get_spell_level(i,1,j));
	j = j + 1;
}
change_pc_skill_pts(i,-1 * (get_char_skill_pts(i)));
alter_stat(i,0,5 - get_stat(i,0)); //- Strength
alter_stat(i,0,5 - get_stat(i,0)); //- Strength
alter_stat(i,1,12 - get_stat(i,1)); // - Dexterity
alter_stat(i,1,12 - get_stat(i,1)); // - Dexterity
alter_stat(i,2,3 - get_stat(i,2)); // - Intelligence
alter_stat(i,2,3 - get_stat(i,2)); // - Intelligence
alter_stat(i,3,5 - get_stat(i,3)); // - Endurance
alter_stat(i,3,5 - get_stat(i,3)); // - Endurance
alter_stat(i,4,15 - get_stat(i,4)); // - Melee Weapons
alter_stat(i,5,0 - get_stat(i,5)); // - Pole Weapons
alter_stat(i,6,0 - get_stat(i,6)); // - Bows
alter_stat(i,7,0 - get_stat(i,7)); // - Thrown Missiles
alter_stat(i,8,0 - get_stat(i,8)); // - Hardiness
alter_stat(i,9,0 - get_stat(i,9)); // - Defense
alter_stat(i,10,0 - get_stat(i,10)); // - Assassination
alter_stat(i,11,0 - get_stat(i,11)); // - Mage Spells
alter_stat(i,12,0 - get_stat(i,12)); // - Priest Spells
alter_stat(i,13,0 - get_stat(i,13)); // - Arcane Lore
alter_stat(i,14,0 - get_stat(i,14)); // - Potion Making
alter_stat(i,15,0 - get_stat(i,15)); // - Tool Use
alter_stat(i,16,0 - get_stat(i,16)); // - Nature Lore
alter_stat(i,17,0 - get_stat(i,17)); // - First Aid
alter_stat(i,18,0 - get_stat(i,18)); // - Luck
alter_stat(i,19,3 - get_stat(i,19)); // - Quick Strike
alter_stat(i,20,0 - get_stat(i,20)); // - Parry
alter_stat(i,21,0 - get_stat(i,21)); // - Blademaster
alter_stat(i,22,0 - get_stat(i,22)); // - Anatomy
alter_stat(i,23,5 - get_stat(i,23)); // - Gymnastics
alter_stat(i,24,0 - get_stat(i,24)); // - Pathfinder
alter_stat(i,25,0 - get_stat(i,25)); // - Magery
alter_stat(i,26,0 - get_stat(i,26)); // - Resistance
alter_stat(i,27,0 - get_stat(i,27)); // - Magical Efficiency
alter_stat(i,28,0 - get_stat(i,28)); // - Lethal Blow
alter_stat(i,29,5 - get_stat(i,29)); // - Riposte
alter_stat(i,30,0 - get_stat(i,30)); // - Sharpshooter

pay_coins(coins_amount());
set_name(i,"Merchant");
reward_give(14);
reward_give(18);
reward_give(451);
reward_give(452);
reward_give(453);
reward_give(454);
reward_give(220);
reward_give(220);
reward_give(220);
reward_give(220);
reward_give(239);
change_char_energy(i,999);
change_char_health(i,-999);
change_char_health(i,999);
revive_party();

level = 0;
while(level <= 63){
	print_str("");
	level = level + 1;
}
print_str_color("Now entering: The Merchant's Tale",3);

break;

beginstate exit_state;
break;

beginstate start_state;
if((get_flag(8,1) == 0) && (get_flag(8,2) == 0))
	set_state_continue(10);
break;

beginstate 10;
if(get_flag(9,0) > 0)
	end();
if(get_flag(8,25) == 1){
	block_entry(1);
	end();
}
set_flag(8,1,1);
if(get_flag(8,2) > 0){
	play_sound(14);
	message_dialog("We hadn't ridden more than a mile before we were suddenly attacked.","A dagger struck Sly in the arm, sending him tumbling from the cart. I didn't even have time to turn towards the source, the forest to the north, before I too was hit.");
	relocate_character(7,22,14);
	set_character_pose(7,14);
	activate_hidden_group(1);
	force_instant_terrain_redraw();
	put_sparkles_on_char(8,11,10);
	run_animation_sound(163);
	pause(3);

	set_character_pose(8,1);
	force_instant_terrain_redraw();
	play_sound(14);
	put_sparkles_on_char(i,7,10);
	put_sparkles_on_char(6,7,10);
	run_animation_sound(163);

	set_character_pose(8,0);
	force_instant_terrain_redraw();

	message_dialog("It was fear dust. It was too late, though, I had already inhaled. I knew I only had a split second of rational thought left before the toxins clouded my mind.","");
	play_sound(117);
	pause(1);

	message_dialog("I stood and prepared myself to leap from the cart, but just as I did so the panicked carthorse bucked.","I was hurled from the cart, and landed heavily on a rock.");
	relocate_character(i,43,45);
	force_view_center(43,45);
	set_character_pose(i,14);
	relocate_character(8,43,44);
	force_instant_terrain_redraw();
	pause(1);
	message_dialog("I must have blacked out for a moment. When I came to Sly had disappeared, and our assailant was standing over me.","Everything was blurred and distorted. I knew that it was the toxin affecting my mind, but I could not fight the overwhelming terror of it all. It was paralyzing, I could not stand to fight or defend myself in any way but to cringe away.");
	message_dialog("_What a shame._","");
	play_sound(18);
	pause(5);
	put_sparkles_on_char(8,11,10);
	run_animation_sound(163);
	pause(3);
	erase_char(8);
	pause(8);
	activate_hidden_group(2);
	relocate_character(10,44,45);
	force_instant_terrain_redraw();
	pause(5);
	set_character_pose(10,1);
	force_instant_terrain_redraw();
	pause(3);
	play_sound(86);
	pause(5);
	put_sparkles_on_char(10,0,10);
	run_animation_sound(165);
	pause(3);
	erase_char(10);
	activate_hidden_group(3);
	relocate_character(9,44,45);
	force_instant_terrain_redraw();
	pause(8);
	small_draw_pic_dialog(301,"Are you alright?");
	move_to_new_town(9,14,8);
	//move_to_new_town(1,14,8);
	end();
}

	block_entry(1);
	relocate_character(i,char_loc_x(i) + 1,13);
	relocate_character(6,char_loc_x(6) + 1,13);
	set_terrain(char_loc_x(i) - 1,13,0);
	set_terrain(char_loc_x(i),13,391);
	set_terrain(char_loc_x(i),13,391);
	force_view_center(char_loc_x(i),char_loc_y(i));
	force_instant_terrain_redraw();
	play_sound(116);
if(get_flag(8,0) == 4)
	message_dialog("I work-- soon to be worked-- for a dispatch service, the Silver Steed Post. Might have heard of us, we work out of Sweetmarch.","Anyhow I was one of their best couriers, which means I got selected for some real high profile jobs-- or low profile rather. Nothing the Silver Steed does is high profile-- that's the whole reason our clients use us.");
if(get_flag(8,0) == 9)
	message_dialog("This particular dispatch was from a wizardry guild in Cyprus. They did a lot of deliveries with us, and were one of our biggest clients. They requested that this particular package be delivered by the best man we had.","Which is how I wound up driving a merchant's cart down the road to Cigosal yesterday morning.");
if(get_flag(8,0) == 14){
	message_dialog("That was when things started getting weird.","");
	relocate_character(7,char_loc_x(6) + 2,13);
	force_instant_terrain_redraw();
	text_bubble_on_char(i,"!");
	pause(4);
	set_flag(8,25,1);
}
inc_flag(8,0,1);  
break;

beginstate 11;
if((get_flag(9,0) > 0) && (get_flag(8,3) == 0)){
	set_flag(8,3,1);
	message_dialog("There it was, sitting undisturbed beneath the seat where I left it. I almost wept I was so relieved, but as it was I actually wound up collapsing.","The adrenaline that had kept me moving even when I was beyond exhaustion left once I had the package in my grasp again. I just lay on the ground panting, trying to get my second wind for the second leg of the trip to Cigosal.");
	change_spec_item(1,1);
	set_character_pose(i,14);
	force_instant_terrain_redraw();
	pause(10);
	play_sound(116);
	pause(2);
	play_sound(116);
	pause(2);
	play_sound(116);
	pause(2);
	play_sound(116);
	pause(2);
	play_sound(116);
	pause(2);
	play_sound(116);
	pause(2);
	play_sound(116);
	pause(2);
	play_sound(116);
	pause(2);
	message_dialog("The sound of hooves announced the cart's approach. I lay there until the cart was nearly on top of me, too tired or just unwilling to get up. Finally I mustered the will to struggle to my feet.","");
	set_terrain(21,12,392);
	set_terrain(20,12,391);
	activate_hidden_group(4);
	set_character_pose(12,8);
	set_character_pose(i,0);
	set_character_facing(i,2);
	force_instant_terrain_redraw();
	pause(2);
	play_sound(117);
	set_char_dialogue_pic(12,307,0);
	begin_talk_mode(5);
}
break;

beginstate 12;
	block_entry(1);
	message_dialog("I had more important things to do. Namely find that package before somebody else did.","");
break;

beginstate 13;
block_entry(1);
message_dialog("I was in a hurry to get to Cigosal, but it was pointless without the package.","");
break;

beginstate 14;
move_to_new_town(10,25,32);
//move_to_new_town(2,25,32);
break;

beginstate 100;
block_entry(1);
break;